/**
 * Created by 徐嘉宾 on 2016/8/10.
 */
$(document).ready(function () {
	var i=0;
	var $modelnone=$(".table tbody tr").eq(5).clone(true);
   	var $deleteoption=$("#addoption").clone();
   	$deleteoption.attr("id","deleteoption").text("删除选项");
   	$deleteoption.insertAfter("#addoption");

   	$("#deleteoption").click(function(){
   		var $tr=$(".table tbody tr")
   		var length=$tr.length;
   		if (length>6) {
   			$tr.eq(length-2).remove();
   			i--;
   		}
   	});

    $("#addoption").click(function(){
    	var $tr=$(".table tbody tr");
    	if ($tr.length>6) {
			var $model=$tr.eq(5).clone(true);
    	}else{
    		var $model=$modelnone;
    	}
    	var xx=getXx(i);
    	$model.find('td:first-child').text(xx).next('td').find(':input:first-child').attr("name",i+5+'').siblings(":input").attr("name",i+5+'_correct');
    	$model.insertBefore($("table tbody tr:last-child"));
    	i++;
    })
});

function getXx(num){
	switch(num+''){
		case '-4':return '选项: A';break;
		case '-3':return '选项: B';break;
		case '-2':return '选项: C';break;
		case '-1':return '选项: D';break;
		case '0':return '选项: E';break;
		case '1':return '选项: F';break;
		case '2':return '选项: G';break;
		case '3':return '选项: H';break;
		case '4':return '选项: I';break;
		case '5':return '选项: J';break;
		case '6':return '选项: K';break;
		case '7':return '选项: L';break;
		case '8':return '选项: M';break;
		case '9':return '选项: N';break;
		case '10':return '选项: O';break;
	}
}